package com.huaxin.hxmoduleworkorder.mapping;

import com.huaxin.hxmoduleworkorder.common.enums.InspectionSendStatus;
import com.huaxin.hxmoduleworkorder.common.enums.OrderNotificationRecipientRole;
import com.huaxin.hxmoduleworkorder.common.enums.OrderNotificationType;
import com.huaxin.hxmoduleworkorder.common.enums.OrderType;
import com.huaxin.hxmoduleworkorder.dto.request.OrderNotificationCreateReqDTO;
import com.huaxin.hxmoduleworkorder.dto.request.OrderNotificationUpdateReqDTO;
import com.huaxin.hxmoduleworkorder.models.OrderNotification;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "spring")
public interface OrderNotificationMapping {
    @Mapping(source = "orderType", target = "orderType", ignore = true)
    @Mapping(source = "recipientRole", target = "recipientRole", ignore = true)
    @Mapping(source = "notificationType", target = "notificationType", ignore = true)
    OrderNotification toEntity(OrderNotificationCreateReqDTO in);

    @AfterMapping
    default void afterMapping(OrderNotificationCreateReqDTO in, @MappingTarget OrderNotification entity) {
        entity.setOrderType(OrderType.of(in.getOrderType()));
        entity.setRecipientRole(OrderNotificationRecipientRole.of(in.getRecipientRole()));
        entity.setNotificationType(OrderNotificationType.of(in.getNotificationType()));
    }

    void updateEntity(OrderNotificationUpdateReqDTO in, @MappingTarget OrderNotification entity);
}